#include <iostream>
#include <string>
#include <jsoncpp/json/json.h>

#include <fstream>

struct stu
{
    std::string name;
    int age;
    double weight;

public:
    void debug()
    {
        std::cout << name << std::endl;
        std::cout << age << std::endl;
        std::cout << weight << std::endl;
    }
};

int main()
{
    //struct stu zs = {"张三", 18, 70};
    std::ifstream in("out.txt");
    if (!in.is_open())
        return 1;
    char buffer[1024];
    in.read(buffer, 1024);
    in.close();

    std::string json_string = buffer;
    Json::Value root;
    Json::Reader reader;
    bool res = reader.parse(json_string, root);

    struct stu zs;
    zs.name = root["name"].asString();
    zs.age = root["age"].asInt();
    zs.weight = root["weight"].asInt();

    zs.debug();

    // //转化成字符串
    // Json::Value root;
    // root["name"] = zs.name;
    // root["age"] = zs.age;
    // root["weight"] = zs.weight;
    // root["self"] = root;

    // // Json::FastWriter writer;
    // Json::StyledWriter writer;
    // std::string str = writer.write(root);

    // std::ofstream out("out.txt");
    // if(!out.is_open())
    // {
    //     std::cout<<str;
    //     return 1;
    // }
    // out<<str;
    // out.close();

    // std::cout<<str;
    return 0;
}